﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class ZLGLListView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindList();
            }
        }

        private void BindList()
        {
            ResourceService service = new ResourceService();
            resourceGridView.DataSource = service.GetResourceByStatus("已处理");
            resourceGridView.DataBind();
        }

        protected void modifyLinkButton_Click(object sender, EventArgs e)
        {
            hftaskID.Value = ((LinkButton)sender).CommandArgument;
            ResourceService service = new ResourceService();
            Resource resouce = service.getResourceByID(long.Parse(hftaskID.Value));
            productTypeLabel.Text = resouce.ProductType;
            problemTypeLabel.Text = resouce.ProblemType;
            descriptionLabel.Text = resouce.ProblemDescription;
            solutionTextBox.Text = resouce.Solution;
            updateModalPopupExtender.Show();
        }

        protected void resourceGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            if (e.NewPageIndex >= 0 && e.NewPageIndex < resourceGridView.PageCount)
            {
                resourceGridView.PageIndex = e.NewPageIndex;
            }
            
            BindList();
        }

        protected void resourceGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF99'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                ((Label)e.Row.FindControl("IDLbl")).Text = (e.Row.RowIndex + 1).ToString();
            }
            if (e.Row.RowType == DataControlRowType.Pager)
            {
                DropDownList pageDDL = e.Row.FindControl("pageDDL") as DropDownList;
                for (int index = 1; index <= resourceGridView.PageCount; index++)
                {
                    pageDDL.Items.Add(index.ToString());
                }
                pageDDL.SelectedValue = (resourceGridView.PageIndex + 1).ToString();
            }
        }

        protected void pageDDL_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList pageDDL = sender as DropDownList;
            resourceGridView.PageIndex = Convert.ToInt32(pageDDL.SelectedIndex);
            PostService service = new PostService();
            resourceGridView.DataSource = service.GetAllPosts("");
            resourceGridView.DataBind();
        }

        protected void resourceGridView_DataBound(object sender, EventArgs e)
        {
            if (resourceGridView.BottomPagerRow != null)
            {
                resourceGridView.BottomPagerRow.Visible = true;
            }
        }
    }
}
